package com.sevenwonders;

import com.sevenwonders.util.Helper;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {

    public static final String KEY_LOCK_ORIENTATION = "lock_orientation";
    public static final String KEY_NAME = "name";
    public static final String KEY_CHOOSE_SIDE = "choose_side";

    private static int lockOrientation = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preferences);
        SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        mPreferences.registerOnSharedPreferenceChangeListener(this);
    }

    public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
        if (key.equalsIgnoreCase(KEY_LOCK_ORIENTATION)) {
            lockOrientation = Helper.updateOrientation(this, lockOrientation);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        mPreferences.unregisterOnSharedPreferenceChangeListener(this);
    }
}
